package com.linwen.javase.desgin_pattern.BigTalkDesignPattenJAVACode._03装饰模式._6装饰器_策略工厂;

/**
 * @ClassName CashContext
 * @Description TODO
 * @Author zero
 * @DATE 2023/7/10 11:11 PM
 * @Version 1.0
 */
public class CashContext {

    private ISale iSale;

    public CashContext(int discount) {
        switch (discount){
            case 1:
                this.iSale = new CashNormal();
                break;
            case 2:
                this.iSale = new CashRebate(0.8);
                break;
            case 3:
                this.iSale = new CashRebate(0.7);
                break;
            case 4:
                this.iSale = new CashReturn(300,100);
                break;
            case 5:
                //先打8折,再满300返100
                CashNormal cn = new CashNormal();
                CashReturn cr1 = new CashReturn(300d,100d);
                CashRebate cr2 = new CashRebate(0.8d);
                cr1.decorate(cn);   //用满300返100算法包装基本的原价算法
                cr2.decorate(cr1);  //打8折算法装饰满300返100算法
                this.iSale = cr2;      //将包装好的算法组合引用传递给cs对象
                break;
            case 6:
                //先满200返50，再打7折
                CashNormal cn2 = new CashNormal();
                CashRebate cr3 = new CashRebate(0.7d);
                CashReturn cr4 = new CashReturn(200d,50d);
                cr3.decorate(cn2);  //用打7折算法包装基本的原价算法
                cr4.decorate(cr3);  //满200返50算法装饰打7折算法
                this.iSale = cr4;      //将包装好的算法组合引用传递给cs对象
                break;
        }
    }


    public double getResult(double price, int num) {
        return this.iSale.acceptCash(price, num);
    }
}
